package org.jeecg.modules.nurse_user_orders.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.base.BaseMap;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.query.QueryGenerator;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.modules.nurse_hospital.entity.NurseHospital;
import org.jeecg.modules.nurse_hospital.service.INurseHospitalService;
import org.jeecg.modules.nurse_user_orders.entity.*;
import org.jeecg.modules.nurse_user_orders.service.*;
import org.jeecg.modules.nurse_user_orders.vo.NurseUserOrdersVo;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import java.util.*;

import org.jeecg.common.util.oConvertUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import java.io.IOException;
import java.util.stream.Collectors;

import org.apache.shiro.authz.annotation.RequiresPermissions;

/**
 * @Description: 用户订单
 * @Author: jeecg-boot
 * @Date: 2024-06-04
 * @Version: V1.0
 */
@Api(tags = "用户订单")
@RestController
@RequestMapping("/nurse_user_orders/nurseUserOrders")
@Slf4j
public class NurseUserOrdersController extends JeecgController<NurseUserOrders, INurseUserOrdersService> {

    @Autowired
    private INurseUserOrdersService nurseUserOrdersService;

    @Autowired
    private INurseUserOrdersDetailService nurseUserOrdersDetailService;

    @Autowired
    private INurseUserOrdersCommentService nurseUserOrdersCommentService;

    @Autowired
    private INurseUserOrdersPreService nurseUserOrdersPreService;

    @Autowired
    private INurseUserOrdersNursesNewService nurseUserOrdersNursesNewService;

    @Resource
    private JeecgBaseConfig jeecgBaseConfig;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private INurseHospitalService nurseHospitalService;

    /**
     * 复制订单
     *
     * @param id  原始订单ID
     * @param num 复制数量
     * @return
     */
    @AutoLog(value = "用户订单-复制订单")
    @ApiOperation(value = "用户订单-复制订单", notes = "用户订单-复制订单")
    @PostMapping(value = "/copyOrder")
    public Result<?> copyOrder(@RequestParam(name = "id") String id, @RequestParam(name = "num") Integer num) {
        try {
            // 检查参数
            if (num <= 0) {
                return Result.error("复制数量必须大于0");
            }

            // 查询原始订单
                // 尝试使用QueryWrapper查询
                QueryWrapper<NurseUserOrders> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("id", id);
                NurseUserOrders originalOrder = nurseUserOrdersService.getOne(queryWrapper);
                
                if (originalOrder == null) {
                    return Result.error("未找到ID为 " + id + " 的订单");
            }

            // 复制订单
            List<NurseUserOrders> newOrders = new ArrayList<>();
            List<NurseUserOrdersDetail> newOrderDetails = new ArrayList<>();

            // 查询原始订单的明细
            QueryWrapper<NurseUserOrdersDetail> detailQueryWrapper = new QueryWrapper<>();
            detailQueryWrapper.eq("order_id", id);
            List<NurseUserOrdersDetail> originalOrderDetails = nurseUserOrdersDetailService.list(detailQueryWrapper);

            for (int i = 0; i < num; i++) {
                // 复制主订单
                NurseUserOrders newOrder = new NurseUserOrders();
                BeanUtils.copyProperties(originalOrder,newOrder);
                
                // 生成新的ID和Code
                String newId = UUID.randomUUID().toString().replace("-", "");
                newOrder.setId(newId);
                // 设置状态为初始状态（如果原始状态为空）
                if (newOrder.getStatus() == null || newOrder.getStatus().isEmpty()) {
                    newOrder.setStatus("0"); // 假设"0"是初始状态
                }
                
                // 清除创建时间和更新时间相关字段
                newOrder.setCreateTime(new Date());
                newOrder.setUpdateTime(null);
                newOrder.setUpdateBy(null);
                newOrders.add(newOrder);

                // 复制订单明细
                for (NurseUserOrdersDetail originalDetail : originalOrderDetails) {
                    NurseUserOrdersDetail newDetail = new NurseUserOrdersDetail();
                    BeanUtils.copyProperties(originalDetail,newDetail);
                    
                    // 设置新的ID和关联的订单ID
                    String detailId = UUID.randomUUID().toString().replace("-", "");
                    newDetail.setId(detailId);
                    newDetail.setOrderId(newId);
                    newDetail.setCreateTime(new Date());
                    newDetail.setUpdateTime(null);
                    newDetail.setUpdateBy(null);
                    
                    newOrderDetails.add(newDetail);
                }
            }

            // 批量保存新订单和订单明细
            nurseUserOrdersService.saveBatch(newOrders);
            nurseUserOrdersDetailService.saveBatch(newOrderDetails);

            JSONObject result = new JSONObject();
            result.put("copiedCount", newOrders.size());
            List<String> newOrderIds = newOrders.stream().map(NurseUserOrders::getId).collect(Collectors.toList());
             newOrderIds.add(id);
            result.put("newOrderIds", newOrderIds);

            return Result.OK("成功复制 " + newOrders.size() + " 个订单", result);
        } catch (Exception e) {
            log.error("复制订单失败: ", e);
            return Result.error("复制订单失败: " + e.getMessage());
        }
    }

    /**
     * 轮询是否有新订单
     *
     * @param timestamp
     * @return
     */
    //@AutoLog(value = "用户订单-轮询是否有新订单")
    @ApiOperation(value = "用户订单-轮询是否有新订单", notes = "用户订单-轮询是否有新订单")
    @GetMapping(value = "/newOrder")
    public Result<?> newOrder(@RequestParam(name = "timestamp") String timestamp) {

        JSONObject jsonObject = new JSONObject();
        if (redisUtil.hasKey("newOrder")) {
            jsonObject.put("timestamp", redisUtil.get("newOrder"));
        } else {
            jsonObject.put("timestamp", timestamp);
        }
        return Result.OK(jsonObject);
    }

    /**
     * 轮询是否有新退款订单
     *
     * @param timestamp
     * @return
     */
    //@AutoLog(value = "用户订单-轮询是否有新退款订单")
    @ApiOperation(value = "用户订单-轮询是否有新退款订单", notes = "用户订单-轮询是否有新退款订单")
    @GetMapping(value = "/refundOrder")
    public Result<?> refundOrder(@RequestParam(name = "timestamp") String timestamp) {
        JSONObject jsonObject = new JSONObject();
        if (redisUtil.hasKey("refundOrder")) {
            jsonObject.put("timestamp", redisUtil.get("refundOrder"));
        } else {
            jsonObject.put("timestamp", timestamp);
        }
        return Result.ok(jsonObject);
    }


    /**
     * 微信列表查询
     *
     * @param beginDate
     * @param endDate
     * @param nurseType
     * @param userId
     * @return
     */
    //@AutoLog(value = "用户订单-微信列表查询")
    @ApiOperation(value = "用户订单-微信列表查询", notes = "用户订单-微信列表查询")
    @GetMapping(value = "/listByWeChat")
    public Result<?> listByWeChat(
            @RequestParam(name = "beginDate", required = true) String beginDate,
            @RequestParam(name = "endDate", required = true) String endDate,
            @RequestParam(name = "nurseType", required = true) String nurseType,
            @RequestParam(name = "userId", required = true) String userId,
            @RequestParam(name = "status", required = true) String status
    ) {
        List<Map<String, Object>> list = nurseUserOrdersService.listByWeChat(beginDate, endDate, nurseType, userId, status);
        return Result.ok(list);
    }

    /**
     * 微信用户订单
     *
     * @param nurseUserOrdersVo
     * @return
     */
    @AutoLog(value = "微信用户订单-添加")
    @ApiOperation(value = "微信用户订单-添加", notes = "微信用户订单-添加")
    @PostMapping(value = "/addByWeChat")
    public Result<?> addByWeChat(@RequestBody NurseUserOrdersVo nurseUserOrdersVo,HttpServletRequest req)  {
        try {
            String org = req.getHeader("sys_org_code");
            String mchId = "A01A03".equals(org.substring(0,6))?"1526566731":"1513682771";
            nurseUserOrdersVo.setSysOrgCode(org);
            BaseMap map = nurseUserOrdersService.addByWeChat(nurseUserOrdersVo,mchId);
            if (map.get("code").equals(200)) {
                nurseUserOrdersService.sendOrderNotification(org, nurseUserOrdersVo.getOrderText());
            }
            // 订单创建成功后，发送消息通知
            return Result.OK(map);
        } catch (Exception e) {
            log.error("微信用户订单添加失败: ", e);
            return Result.error("订单添加失败: " + e.getMessage());
        }
    }

    /**
     * 微信支付用户订单
     *
     * @param outTradeNo
     * @return
     */
    @AutoLog(value = "微信用户订单-支付")
    @ApiOperation(value = "微信用户订单-支付", notes = "微信用户订单-支付")
    @PostMapping(value = "/payByWeChat")
    public Result<?> payByWeChat(@RequestParam(name = "outTradeNo") String outTradeNo) {
        BaseMap map = nurseUserOrdersService.payByWeChat(outTradeNo);
        return Result.OK(map);
    }


    /**
     * 微信支付用户订单退款
     *
     * @param outTradeNo
     * @return
     */
    @AutoLog(value = "微信用户订单-退款")
    @ApiOperation(value = "微信用户订单-退款", notes = "微信用户订单-退款")
    @GetMapping(value = "/refund")
    public Result<?> refund(@RequestParam(name = "outTradeNo") String outTradeNo) {
        BaseMap map = nurseUserOrdersService.refund(outTradeNo);
        return Result.OK(map);
    }

    /**
     * 微信用户订单关闭
     *
     * @param outTradeNo
     * @return
     */
    @AutoLog(value = "微信用户订单-关闭")
    @ApiOperation(value = "微信用户订单-关闭", notes = "微信用户订单-关闭")
    @GetMapping(value = "/closeByWeChat")
    public Result<String> closeByWeChat(@RequestParam(name = "outTradeNo") String outTradeNo) {
        nurseUserOrdersService.closeByWeChat(outTradeNo);
        return Result.OK("关闭成功！");
    }

    /**
     * 微信用户订单支付回调
     *
     * @param request
     * @return
     */
    @AutoLog(value = "微信用户订单-支付回调")
    @ApiOperation(value = "微信用户订单-支付回调", notes = "微信用户订单-支付回调")
    @PostMapping(value = "/payNotify")
    public Result<?> payNotify(HttpServletRequest request) {
        nurseUserOrdersService.payNotify(request,"1513682771");
        return Result.OK();
    }

    /**
     * 微信用户订单支付回调
     *
     * @param request
     * @return
     */
    @AutoLog(value = "微信用户订单-支付回调")
    @ApiOperation(value = "微信用户订单-支付回调", notes = "微信用户订单-支付回调")
    @PostMapping(value = "/payNotifyah")
    public Result<?> payNotifyah(HttpServletRequest request) {
        nurseUserOrdersService.payNotify(request,"1526566731");
        return Result.OK();
    }

    /**
     * 微信用户订单退费回调
     *
     * @param request
     * @return
     */
    @AutoLog(value = "微信用户订单-退费回调")
    @ApiOperation(value = "微信用户订单-退费回调", notes = "微信用户订单-退费回调")
    @PostMapping(value = "/refundNotify")
    public Result<?> refundNotify(HttpServletRequest request) {
        nurseUserOrdersService.refundNotify(request,"1513682771");
        return Result.OK();
    }
    @AutoLog(value = "微信用户订单-退费回调")
    @ApiOperation(value = "微信用户订单-退费回调", notes = "微信用户订单-退费回调")
    @PostMapping(value = "/refundNotifyah")
    public Result<?> refundNotifyah(HttpServletRequest request) {
        nurseUserOrdersService.refundNotify(request,"1526566731");
        return Result.OK();
    }

    /**
     * 微信过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "用户订单-微信过id查询")
    @ApiOperation(value = "用户订单-微信过id查询", notes = "用户订单-微信过id查询")
    @GetMapping(value = "/queryByWeChat")
    public Result<?> queryByWeChat(@RequestParam(name = "id") String id) {
        NurseUserOrders nurseUserOrders = nurseUserOrdersService.getOne(new QueryWrapper<NurseUserOrders>().
                select("id", "family_name", "remark", "phone", "hospital_name", "dept_name", "bed_name", "begin_date", "end_date", "area_name", "address", "expiry_time","status","is_go_home","order_json").eq("id", id));

        if (nurseUserOrders == null) {
            return Result.error("未找到对应数据");
        }

        QueryWrapper queryWrapper = new QueryWrapper<NurseUserOrdersDetail>().eq("order_id", id);
        List<NurseUserOrdersDetail> nurseUserOrdersDetails = nurseUserOrdersDetailService.list(queryWrapper);

        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(nurseUserOrders);
        jsonObject.put("nurseUserOrdersDetails", nurseUserOrdersDetails);
        return Result.OK(jsonObject);

    }


    /**
     * 微信用户订单评价
     *
     * @param nurseUserOrdersComment
     * @return
     */
    @AutoLog(value = "微信用户订单评价-添加")
    @ApiOperation(value = "微信用户订单评价-添加", notes = "微信用户订单评价-添加")
    @PostMapping(value = "/addComment")
    public Result<String> addComment(@RequestBody NurseUserOrdersComment nurseUserOrdersComment) {
        String orderId = nurseUserOrdersComment.getOrderId();

        NurseUserOrders nurseUserOrders = nurseUserOrdersService.getById(orderId);

        nurseUserOrdersComment.setTitle(nurseUserOrders.getOrderText());
        nurseUserOrdersComment.setNurseType(nurseUserOrders.getNurseType());

        nurseUserOrdersCommentService.save(nurseUserOrdersComment);

        return Result.OK("添加成功！");
    }

    /**
     * 评论列表查询
     *
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "用户订单-评论列表查询")
    @ApiOperation(value = "用户订单-评论列表查询", notes = "用户订单-评论列表查询")
    @GetMapping(value = "/commentList")
    @PermissionData(pageComponent = "nurse/nurse_user_orders_comment/NurseUserOrdersCommentList")
    public Result<IPage<NurseUserOrdersComment>> commentList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "rate", required = false) Integer rate,
            @RequestParam(name = "createBy", required = false) String createBy,
            @RequestParam(name = "status", required = false) String status,
            @RequestParam(name = "beginDate", required = false) String beginDate,
            @RequestParam(name = "endDate", required = false) String endDate,
            @RequestParam(name = "userId", required = false) String userId,
            HttpServletRequest req) {
        QueryWrapper queryWrapper = new QueryWrapper();

        if (oConvertUtils.isNotEmpty(rate)) {
            queryWrapper.eq("rate", rate);
        }

        if (oConvertUtils.isNotEmpty(createBy)) {
            queryWrapper.like("create_by", createBy);
        }

        if (oConvertUtils.isNotEmpty(status)) {
            queryWrapper.eq("status", status);
        }
        if (oConvertUtils.isNotEmpty(userId)) {
            queryWrapper.eq("user_id", userId);
        }

        if (oConvertUtils.isNotEmpty(beginDate) && oConvertUtils.isNotEmpty(endDate)) {
            queryWrapper.between("create_time", beginDate, endDate);
        }

        Page<NurseUserOrdersComment> page = new Page<>(pageNo, pageSize);
        IPage<NurseUserOrdersComment> pageList = nurseUserOrdersCommentService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 导出评论excel
     *
     * @param req
     */
    @RequiresPermissions("nurse_user_orders_comment:nurse_user_orders_comment:exportXls")
    @RequestMapping(value = "/exportCommentXls")
    public ModelAndView exportCommentXls(@RequestParam(name = "rate", required = false) Integer rate,
                                         @RequestParam(name = "createBy", required = false) String createBy,
                                         @RequestParam(name = "status", required = false) String status,
                                         @RequestParam(name = "beginDate", required = false) String beginDate,
                                         @RequestParam(name = "endDate", required = false) String endDate,
                                         HttpServletRequest req) {
        // Step.1 组装查询条件

        QueryWrapper queryWrapper = new QueryWrapper();

        if (oConvertUtils.isNotEmpty(rate)) {
            queryWrapper.eq("rate", rate);
        }

        if (oConvertUtils.isNotEmpty(createBy)) {
            queryWrapper.like("create_by", createBy);
        }

        if (oConvertUtils.isNotEmpty(status)) {
            queryWrapper.eq("status", status);
        }
        if (oConvertUtils.isNotEmpty(beginDate) && oConvertUtils.isNotEmpty(endDate)) {
            queryWrapper.between("create_time", beginDate, endDate);
        }
//        QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        // 过滤选中数据
        String selections = req.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            queryWrapper.in("id", selectionList);
        }
        // Step.2 获取导出数据
        List<NurseUserOrdersComment> exportList = nurseUserOrdersCommentService.list(queryWrapper);

        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, "订单评论");
        mv.addObject(NormalExcelConstants.CLASS, NurseUserOrdersComment.class);
        //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
        ExportParams exportParams = new ExportParams("订单评论报表", "导出人:" + sysUser.getRealname(), "订单评论");
        exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload());
        //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
        mv.addObject(NormalExcelConstants.PARAMS, exportParams);
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }

    /*---------------------------------主表处理-begin-------------------------------------*/

    /**
     * 分页列表查询
     *
     * @param nurseUserOrders
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "用户订单-分页列表查询")
    @ApiOperation(value = "用户订单-分页列表查询", notes = "用户订单-分页列表查询")
    @GetMapping(value = "/list")
    @PermissionData(pageComponent = "nurse/nurse_user_orders/NurseUserOrdersList")
    public Result<IPage<NurseUserOrders>> queryPageList(NurseUserOrders nurseUserOrders,
                                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                        HttpServletRequest req) {
        QueryWrapper<NurseUserOrders> queryWrapper = QueryGenerator.initQueryWrapper(nurseUserOrders, req.getParameterMap());
        Page<NurseUserOrders> page = new Page<NurseUserOrders>(pageNo, pageSize);
        IPage<NurseUserOrders> pageList = nurseUserOrdersService.page(page, queryWrapper);
        return Result.OK(pageList);
    }


    /**
     * 分页列表查询
     *
     * @param nurseUserOrders
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "用户订单-分页列表查询")
    @ApiOperation(value = "用户订单-分页列表查询", notes = "用户订单-分页列表查询")
    @GetMapping(value = "/listAll")
    public Result<IPage<NurseUserOrders>> queryPageListAll(NurseUserOrders nurseUserOrders,
                                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                        HttpServletRequest req) {
        QueryWrapper<NurseUserOrders> queryWrapper = QueryGenerator.initQueryWrapper(nurseUserOrders, req.getParameterMap());
        Page<NurseUserOrders> page = new Page<NurseUserOrders>(pageNo, pageSize);
        SysUser sysuser= sysUserService.getLoginUser();

        List<NurseHospital> list = nurseHospitalService.list(new LambdaQueryWrapper<NurseHospital>().eq(NurseHospital::getSysOrgCode,sysuser.getOrgCode()));
        if(!list.isEmpty()){
            queryWrapper.eq("hospital",list.get(0).getId());
        }
        IPage<NurseUserOrders> pageList = nurseUserOrdersService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param nurseUserOrders
     * @return
     */
    @AutoLog(value = "用户订单-添加")
    @ApiOperation(value = "用户订单-添加", notes = "用户订单-添加")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody NurseUserOrders nurseUserOrders) {
        nurseUserOrdersService.save(nurseUserOrders);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param nurseUserOrders
     * @return
     */
    @AutoLog(value = "用户订单-编辑")
    @ApiOperation(value = "用户订单-编辑", notes = "用户订单-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody NurseUserOrders nurseUserOrders) {
        nurseUserOrdersService.updateById(nurseUserOrders);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "用户订单-通过id删除")
    @ApiOperation(value = "用户订单-通过id删除", notes = "用户订单-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        nurseUserOrdersService.delMain(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "用户订单-批量删除")
    @ApiOperation(value = "用户订单-批量删除", notes = "用户订单-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.nurseUserOrdersService.delBatchMain(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 导出
     *
     * @return
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, NurseUserOrders nurseUserOrders) {
        return super.exportXls(request, nurseUserOrders, NurseUserOrders.class, "用户订单");
    }

    /**
     * 导入
     *
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, NurseUserOrders.class);
    }
    /*---------------------------------主表处理-end-------------------------------------*/


    /*--------------------------------子表处理-用户订单明细-begin----------------------------------------------*/

    /**
     * 通过主表ID查询
     *
     * @return
     */
    //@AutoLog(value = "用户订单明细-通过主表ID查询")
    @ApiOperation(value = "用户订单明细-通过主表ID查询", notes = "用户订单明细-通过主表ID查询")
    @GetMapping(value = "/listNurseUserOrdersDetailByMainId")
    public Result<IPage<NurseUserOrdersDetail>> listNurseUserOrdersDetailByMainId(NurseUserOrdersDetail nurseUserOrdersDetail,
                                                                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                                  HttpServletRequest req) {
        QueryWrapper<NurseUserOrdersDetail> queryWrapper = QueryGenerator.initQueryWrapper(nurseUserOrdersDetail, req.getParameterMap());
        Page<NurseUserOrdersDetail> page = new Page<NurseUserOrdersDetail>(pageNo, pageSize);
        IPage<NurseUserOrdersDetail> pageList = nurseUserOrdersDetailService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param nurseUserOrdersDetail
     * @return
     */
    @AutoLog(value = "用户订单明细-添加")
    @ApiOperation(value = "用户订单明细-添加", notes = "用户订单明细-添加")
    @PostMapping(value = "/addNurseUserOrdersDetail")
    public Result<String> addNurseUserOrdersDetail(@RequestBody NurseUserOrdersDetail nurseUserOrdersDetail) {
        nurseUserOrdersDetailService.save(nurseUserOrdersDetail);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param nurseUserOrdersDetail
     * @return
     */
    @AutoLog(value = "用户订单明细-编辑")
    @ApiOperation(value = "用户订单明细-编辑", notes = "用户订单明细-编辑")
    @RequestMapping(value = "/editNurseUserOrdersDetail", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> editNurseUserOrdersDetail(@RequestBody NurseUserOrdersDetail nurseUserOrdersDetail) {
        nurseUserOrdersDetailService.updateById(nurseUserOrdersDetail);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "用户订单明细-通过id删除")
    @ApiOperation(value = "用户订单明细-通过id删除", notes = "用户订单明细-通过id删除")
    @DeleteMapping(value = "/deleteNurseUserOrdersDetail")
    public Result<String> deleteNurseUserOrdersDetail(@RequestParam(name = "id", required = true) String id) {
        nurseUserOrdersDetailService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "用户订单明细-批量删除")
    @ApiOperation(value = "用户订单明细-批量删除", notes = "用户订单明细-批量删除")
    @DeleteMapping(value = "/deleteBatchNurseUserOrdersDetail")
    public Result<String> deleteBatchNurseUserOrdersDetail(@RequestParam(name = "ids", required = true) String ids) {
        this.nurseUserOrdersDetailService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 导出
     *
     * @return
     */
    @RequestMapping(value = "/exportNurseUserOrdersDetail")
    public ModelAndView exportNurseUserOrdersDetail(HttpServletRequest request, NurseUserOrdersDetail nurseUserOrdersDetail) {
        // Step.1 组装查询条件
        QueryWrapper<NurseUserOrdersDetail> queryWrapper = QueryGenerator.initQueryWrapper(nurseUserOrdersDetail, request.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        // Step.2 获取导出数据
        List<NurseUserOrdersDetail> pageList = nurseUserOrdersDetailService.list(queryWrapper);
        List<NurseUserOrdersDetail> exportList = null;

        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
        } else {
            exportList = pageList;
        }

        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, "用户订单明细");
        mv.addObject(NormalExcelConstants.CLASS, NurseUserOrdersDetail.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("用户订单明细报表", "导出人:" + sysUser.getRealname(), "用户订单明细"));
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }

    /**
     * 导入
     *
     * @return
     */
    @RequestMapping(value = "/importNurseUserOrdersDetail/{mainId}")
    public Result<?> importNurseUserOrdersDetail(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            // 获取上传文件对象
            MultipartFile file = entity.getValue();
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<NurseUserOrdersDetail> list = ExcelImportUtil.importExcel(file.getInputStream(), NurseUserOrdersDetail.class, params);
                for (NurseUserOrdersDetail temp : list) {
                    temp.setOrderId(mainId);
                }
                long start = System.currentTimeMillis();
                nurseUserOrdersDetailService.saveBatch(list);
                log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
                return Result.OK("文件导入成功！数据行数：" + list.size());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("文件导入失败:" + e.getMessage());
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-用户订单明细-end----------------------------------------------*/

    /*--------------------------------子表处理-用户订单评论-begin----------------------------------------------*/

    /**
     * 通过主表ID查询
     *
     * @return
     */
    //@AutoLog(value = "用户订单评论-通过主表ID查询")
    @ApiOperation(value = "用户订单评论-通过主表ID查询", notes = "用户订单评论-通过主表ID查询")
    @GetMapping(value = "/listNurseUserOrdersCommentByMainId")
    public Result<IPage<NurseUserOrdersComment>> listNurseUserOrdersCommentByMainId(NurseUserOrdersComment nurseUserOrdersComment,
                                                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                                    HttpServletRequest req) {
        QueryWrapper<NurseUserOrdersComment> queryWrapper = QueryGenerator.initQueryWrapper(nurseUserOrdersComment, req.getParameterMap());
        Page<NurseUserOrdersComment> page = new Page<NurseUserOrdersComment>(pageNo, pageSize);
        IPage<NurseUserOrdersComment> pageList = nurseUserOrdersCommentService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param nurseUserOrdersComment
     * @return
     */
    @AutoLog(value = "用户订单评论-添加")
    @ApiOperation(value = "用户订单评论-添加", notes = "用户订单评论-添加")
    @PostMapping(value = "/addNurseUserOrdersComment")
    public Result<String> addNurseUserOrdersComment(@RequestBody NurseUserOrdersComment nurseUserOrdersComment) {
        nurseUserOrdersCommentService.save(nurseUserOrdersComment);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param nurseUserOrdersComment
     * @return
     */
    @AutoLog(value = "用户订单评论-编辑")
    @ApiOperation(value = "用户订单评论-编辑", notes = "用户订单评论-编辑")
    @RequestMapping(value = "/editNurseUserOrdersComment", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> editNurseUserOrdersComment(@RequestBody NurseUserOrdersComment nurseUserOrdersComment) {
        nurseUserOrdersCommentService.updateById(nurseUserOrdersComment);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "用户订单评论-通过id删除")
    @ApiOperation(value = "用户订单评论-通过id删除", notes = "用户订单评论-通过id删除")
    @DeleteMapping(value = "/deleteNurseUserOrdersComment")
    public Result<String> deleteNurseUserOrdersComment(@RequestParam(name = "id", required = true) String id) {
        nurseUserOrdersCommentService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "用户订单评论-批量删除")
    @ApiOperation(value = "用户订单评论-批量删除", notes = "用户订单评论-批量删除")
    @DeleteMapping(value = "/deleteBatchNurseUserOrdersComment")
    public Result<String> deleteBatchNurseUserOrdersComment(@RequestParam(name = "ids", required = true) String ids) {
        this.nurseUserOrdersCommentService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 导出
     *
     * @return
     */
    @RequestMapping(value = "/exportNurseUserOrdersComment")
    public ModelAndView exportNurseUserOrdersComment(HttpServletRequest request, NurseUserOrdersComment nurseUserOrdersComment) {
        // Step.1 组装查询条件
        QueryWrapper<NurseUserOrdersComment> queryWrapper = QueryGenerator.initQueryWrapper(nurseUserOrdersComment, request.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        // Step.2 获取导出数据
        List<NurseUserOrdersComment> pageList = nurseUserOrdersCommentService.list(queryWrapper);
        List<NurseUserOrdersComment> exportList = null;

        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
        } else {
            exportList = pageList;
        }

        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, "用户订单评论");
        mv.addObject(NormalExcelConstants.CLASS, NurseUserOrdersComment.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("用户订单评论报表", "导出人:" + sysUser.getRealname(), "用户订单评论"));
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }

    /**
     * 导入
     *
     * @return
     */
    @RequestMapping(value = "/importNurseUserOrdersComment/{mainId}")
    public Result<?> importNurseUserOrdersComment(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            // 获取上传文件对象
            MultipartFile file = entity.getValue();
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<NurseUserOrdersComment> list = ExcelImportUtil.importExcel(file.getInputStream(), NurseUserOrdersComment.class, params);
                for (NurseUserOrdersComment temp : list) {
                    temp.setOrderId(mainId);
                }
                long start = System.currentTimeMillis();
                nurseUserOrdersCommentService.saveBatch(list);
                log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
                return Result.OK("文件导入成功！数据行数：" + list.size());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("文件导入失败:" + e.getMessage());
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-用户订单评论-end----------------------------------------------*/

    /*--------------------------------子表处理-用户订单预付款-begin----------------------------------------------*/

    /**
     * 通过主表ID查询
     *
     * @return
     */
    //@AutoLog(value = "用户订单预付款-通过主表ID查询")
    @ApiOperation(value = "用户订单预付款-通过主表ID查询", notes = "用户订单预付款-通过主表ID查询")
    @GetMapping(value = "/listNurseUserOrdersPreByMainId")
    public Result<IPage<NurseUserOrdersPre>> listNurseUserOrdersPreByMainId(NurseUserOrdersPre nurseUserOrdersPre,
                                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                            HttpServletRequest req) {
        QueryWrapper<NurseUserOrdersPre> queryWrapper = QueryGenerator.initQueryWrapper(nurseUserOrdersPre, req.getParameterMap());
        Page<NurseUserOrdersPre> page = new Page<NurseUserOrdersPre>(pageNo, pageSize);
        IPage<NurseUserOrdersPre> pageList = nurseUserOrdersPreService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param nurseUserOrdersPre
     * @return
     */
    @AutoLog(value = "用户订单预付款-添加")
    @ApiOperation(value = "用户订单预付款-添加", notes = "用户订单预付款-添加")
    @PostMapping(value = "/addNurseUserOrdersPre")
    public Result<String> addNurseUserOrdersPre(@RequestBody NurseUserOrdersPre nurseUserOrdersPre) {
        nurseUserOrdersPreService.save(nurseUserOrdersPre);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param nurseUserOrdersPre
     * @return
     */
    @AutoLog(value = "用户订单预付款-编辑")
    @ApiOperation(value = "用户订单预付款-编辑", notes = "用户订单预付款-编辑")
    @RequestMapping(value = "/editNurseUserOrdersPre", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> editNurseUserOrdersPre(@RequestBody NurseUserOrdersPre nurseUserOrdersPre) {
        nurseUserOrdersPreService.updateById(nurseUserOrdersPre);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "用户订单预付款-通过id删除")
    @ApiOperation(value = "用户订单预付款-通过id删除", notes = "用户订单预付款-通过id删除")
    @DeleteMapping(value = "/deleteNurseUserOrdersPre")
    public Result<String> deleteNurseUserOrdersPre(@RequestParam(name = "id", required = true) String id) {
        nurseUserOrdersPreService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "用户订单预付款-批量删除")
    @ApiOperation(value = "用户订单预付款-批量删除", notes = "用户订单预付款-批量删除")
    @DeleteMapping(value = "/deleteBatchNurseUserOrdersPre")
    public Result<String> deleteBatchNurseUserOrdersPre(@RequestParam(name = "ids", required = true) String ids) {
        this.nurseUserOrdersPreService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 导出
     *
     * @return
     */
    @RequestMapping(value = "/exportNurseUserOrdersPre")
    public ModelAndView exportNurseUserOrdersPre(HttpServletRequest request, NurseUserOrdersPre nurseUserOrdersPre) {
        // Step.1 组装查询条件
        QueryWrapper<NurseUserOrdersPre> queryWrapper = QueryGenerator.initQueryWrapper(nurseUserOrdersPre, request.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        // Step.2 获取导出数据
        List<NurseUserOrdersPre> pageList = nurseUserOrdersPreService.list(queryWrapper);
        List<NurseUserOrdersPre> exportList = null;

        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
        } else {
            exportList = pageList;
        }

        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, "用户订单预付款");
        mv.addObject(NormalExcelConstants.CLASS, NurseUserOrdersPre.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("用户订单预付款报表", "导出人:" + sysUser.getRealname(), "用户订单预付款"));
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }

    /**
     * 导入
     *
     * @return
     */
    @RequestMapping(value = "/importNurseUserOrdersPre/{mainId}")
    public Result<?> importNurseUserOrdersPre(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            // 获取上传文件对象
            MultipartFile file = entity.getValue();
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<NurseUserOrdersPre> list = ExcelImportUtil.importExcel(file.getInputStream(), NurseUserOrdersPre.class, params);
                for (NurseUserOrdersPre temp : list) {
                    temp.setOrderId(mainId);
                }
                long start = System.currentTimeMillis();
                nurseUserOrdersPreService.saveBatch(list);
                log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
                return Result.OK("文件导入成功！数据行数：" + list.size());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("文件导入失败:" + e.getMessage());
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.error("文件导入失败！");
    }

    /*--------------------------------子表处理-用户订单预付款-end----------------------------------------------*/


    /*--------------------------------子表处理-用户订单分配护工表-begin----------------------------------------------*/
    /**
     * 通过主表ID查询
     * @return
     */
    //@AutoLog(value = "用户订单分配护工表-通过主表ID查询")
    @ApiOperation(value="用户订单分配护工表-通过主表ID查询", notes="用户订单分配护工表-通过主表ID查询")
    @GetMapping(value = "/listNurseUserOrdersNursesNewByMainId")
    public Result<IPage<NurseUserOrdersNursesNew>> listNurseUserOrdersNursesNewByMainId(NurseUserOrdersNursesNew nurseUserOrdersNursesNew,
                                                                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                                        HttpServletRequest req) {
        QueryWrapper<NurseUserOrdersNursesNew> queryWrapper = QueryGenerator.initQueryWrapper(nurseUserOrdersNursesNew, req.getParameterMap());
        Page<NurseUserOrdersNursesNew> page = new Page<NurseUserOrdersNursesNew>(pageNo, pageSize);
        IPage<NurseUserOrdersNursesNew> pageList = nurseUserOrdersNursesNewService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     * @param nurseUserOrdersNursesNew
     * @return
     */
    @AutoLog(value = "用户订单分配护工表-添加")
    @ApiOperation(value="用户订单分配护工表-添加", notes="用户订单分配护工表-添加")
    @PostMapping(value = "/addNurseUserOrdersNursesNew")
    public Result<String> addNurseUserOrdersNursesNew(@RequestBody NurseUserOrdersNursesNew nurseUserOrdersNursesNew) {
        nurseUserOrdersNursesNewService.save(nurseUserOrdersNursesNew);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     * @param nurseUserOrdersNursesNew
     * @return
     */
    @AutoLog(value = "用户订单分配护工表-编辑")
    @ApiOperation(value="用户订单分配护工表-编辑", notes="用户订单分配护工表-编辑")
    @RequestMapping(value = "/editNurseUserOrdersNursesNew", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<String> editNurseUserOrdersNursesNew(@RequestBody NurseUserOrdersNursesNew nurseUserOrdersNursesNew) {
        nurseUserOrdersNursesNewService.updateById(nurseUserOrdersNursesNew);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     * @param id
     * @return
     */
    @AutoLog(value = "用户订单分配护工表-通过id删除")
    @ApiOperation(value="用户订单分配护工表-通过id删除", notes="用户订单分配护工表-通过id删除")
    @DeleteMapping(value = "/deleteNurseUserOrdersNursesNew")
    public Result<String> deleteNurseUserOrdersNursesNew(@RequestParam(name="id",required=true) String id) {
        nurseUserOrdersNursesNewService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @AutoLog(value = "用户订单分配护工表-批量删除")
    @ApiOperation(value="用户订单分配护工表-批量删除", notes="用户订单分配护工表-批量删除")
    @DeleteMapping(value = "/deleteBatchNurseUserOrdersNursesNew")
    public Result<String> deleteBatchNurseUserOrdersNursesNew(@RequestParam(name="ids",required=true) String ids) {
        this.nurseUserOrdersNursesNewService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportNurseUserOrdersNursesNew")
    public ModelAndView exportNurseUserOrdersNursesNew(HttpServletRequest request, NurseUserOrdersNursesNew nurseUserOrdersNursesNew) {
        // Step.1 组装查询条件
        QueryWrapper<NurseUserOrdersNursesNew> queryWrapper = QueryGenerator.initQueryWrapper(nurseUserOrdersNursesNew, request.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        // Step.2 获取导出数据
        List<NurseUserOrdersNursesNew> pageList = nurseUserOrdersNursesNewService.list(queryWrapper);
        List<NurseUserOrdersNursesNew> exportList = null;

        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
        } else {
            exportList = pageList;
        }

        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, "用户订单分配护工表");
        mv.addObject(NormalExcelConstants.CLASS, NurseUserOrdersNursesNew.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("用户订单分配护工表报表", "导出人:" + sysUser.getRealname(), "用户订单分配护工表"));
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }

    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importNurseUserOrdersNursesNew/{mainId}")
    public Result<?> importNurseUserOrdersNursesNew(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            // 获取上传文件对象
            MultipartFile file = entity.getValue();
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<NurseUserOrdersNursesNew> list = ExcelImportUtil.importExcel(file.getInputStream(), NurseUserOrdersNursesNew.class, params);
                for (NurseUserOrdersNursesNew temp : list) {
                    temp.setOrderId(mainId);
                }
                long start = System.currentTimeMillis();
                nurseUserOrdersNursesNewService.saveBatch(list);
                log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
                return Result.OK("文件导入成功！数据行数：" + list.size());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("文件导入失败:" + e.getMessage());
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.error("文件导入失败！");
    }
    /*--------------------------------子表处理-用户订单分配护工表-end----------------------------------------------*/

}
